cd ""
use "coef_wide.dta", clear

* Table C1
encode study, g(study_code)

* HL
ologit HL_7 global i.issue influence  distance_HL ln_n pre_diff_HL i.study_code  if p_HL_10==1 
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)') sortvar(us influence  party global issue distance_HL distance_HM ln_n) lab replace

*US
ologit HL_7 global i.issue i.party influence  distance_HL ln_n pre_diff_HL i.study_code if us==1 & p_HL_10==1 
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)') sortvar(us influence  party global issue distance_HL distance_HM ln_n) lab append

* HM
ologit HM_7 global i.issue influence  distance_HM ln_n pre_diff_HM i.study_code if p_HM_10==1 
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)') sortvar(us influence  party global issue distance_HL distance_HM ln_n) lab append

*US
ologit HM_7 global i.issue i.party influence  distance_HM ln_n pre_diff_HM i.study_code if us==1 & p_HM_10==1
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)') sortvar(us influence  party global issue distance_HL distance_HM ln_n) lab append

* ambiguous cases
logit rescale_p_HL_10 global i.issue i.party influence  distance_HL  ln_n pre_diff_HL i.study_code
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)') sortvar(us influence  party global issue distance_HL distance_HM ln_n) lab append

logit rescale_p_HM_10 global i.issue i.party influence  distance_HM  ln_n pre_diff_HM i.study_code
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)') sortvar(us influence  party global issue distance_HL distance_HM ln_n) lab append

* Figures C1-C2
**** calculated predicted probabilities to graph - this code is for the high vs low comparison
use "coef_wide.dta", clear

encode study, g(study_code)
ologit HL_7 global i.issue influence distance_HL ln_n pre_diff_HL i.study_code if p_HL_10==1
predict pr* if e(sample)
keep if e(sample)


* Global
preserve
keep pr1-pr7 global
foreach v of varlist pr1-pr7 {
bysort global: egen re_`v'=mean(`v')
}

label define yesno_gl  0 "No" 1 "Yes"
label values global yesno_gl


keep global re_*
duplicates drop re_pr1, force
reshape long re_pr, i(global) j(HL_7)

ren global lab
decode lab, g(re_lab)
g byvar="General political ideology"


save "prpHL_global_FE.dta", replace
restore

* issue
preserve
keep pr1-pr7 issue
foreach v of varlist pr1-pr7 {
bysort issue: egen re_`v'=mean(`v')
}

keep issue re_*
duplicates drop re_pr1, force
reshape long re_pr, i(issue) j(HL_7)

ren issue lab
decode lab, g(re_lab)
g byvar="Issue"

save "prpHL_issue_FE.dta", replace
restore


* Influence
preserve
keep pr1-pr7 influence
foreach v of varlist pr1-pr7 {
bysort influence: egen re_`v'=mean(`v')
}

keep influence re_*
duplicates drop re_pr1, force
reshape long re_pr, i(influence) j(HL_7)

ren influence lab
decode lab, g(re_lab)
g byvar="N of groups included in a model"

save "prpHL_influence_FE.dta", replace
restore

* Partisanship
use "coef_wide.dta", clear

encode study, g(study_code)
ologit HL_7 global i.issue i.party influence distance_HL ln_n pre_diff_HL i.study_code if us==1 & p_HL_10==1
predict pr* if e(sample)
keep if e(sample)

keep pr1-pr7 party
foreach v of varlist pr1-pr7 {
bysort party: egen re_`v'=mean(`v')
}

keep party re_*
duplicates drop re_pr1, force
reshape long re_pr, i(party) j(HL_7)

ren party lab
decode lab, g(re_lab)
g byvar="Partisanship"

save "prpHL_party_FE.dta", replace

use "prpHL_global_FE.dta", clear
append using "prpHL_issue_FE.dta"
append using "prpHL_influence_FE.dta"
append using "prpHL_party_FE.dta"

g id=1 if byvar=="N of groups included in a model"
replace id=2 if byvar=="Partisanship"
replace id=3 if byvar=="General political ideology"
replace id=4 if byvar=="Issue"

label values lab .

save "prpHL_all_FE.dta", replace


**** calculated predicted probabilities to graph - this code is for the high vs middle comparison
use "coef_wide.dta", clear
label define lb_us  0 "Not U.S." 1 "U.S."
label values us lb_us


encode study, g(study_code)
ologit HM_7 global i.issue influence distance_HM ln_n pre_diff_HM i.study_code if p_HM_10==1
predict HMpr* if e(sample)
keep if e(sample)


* global
preserve
keep HMpr1-HMpr7 global
foreach v of varlist HMpr1-HMpr7 {
bysort global: egen re_`v'=mean(`v')
}

label define yesno_gl  0 "No" 1 "Yes"
label values global yesno_gl

keep global re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(global) j(HM_7)
ren global lab
decode lab, g(re_lab)
g byvar="General political ideology"

save "prpHM_global_FE.dta", replace
restore

* issue
preserve
keep HMpr1-HMpr7 issue
foreach v of varlist HMpr1-HMpr7 {
bysort issue: egen re_`v'=mean(`v')
}

keep issue re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(issue) j(HM_7)

ren issue lab
decode lab, g(re_lab)
g byvar="Issue"

save "prpHM_issue_FE.dta", replace
restore

* Influence
preserve
keep HMpr1-HMpr7 influence
foreach v of varlist HMpr1-HMpr7 {
bysort influence: egen re_`v'=mean(`v')
}

keep influence re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(influence) j(HM_7)

ren influence lab
decode lab, g(re_lab)
g byvar="N of groups included in a model"


save "prpHM_influence_FE.dta", replace
restore


* party
use "coef_wide.dta", clear
label define lb_us  0 "Not U.S." 1 "U.S."
label values us lb_us

encode study, g(study_code)
ologit HM_7 global i.issue i.party influence distance_HM ln_n pre_diff_HM i.study_code if us==1 & p_HL_10==1
predict HMpr* if e(sample)
keep if e(sample)

keep HMpr1-HMpr7 party
foreach v of varlist HMpr1-HMpr7 {
bysort party: egen re_`v'=mean(`v')
}

keep party re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(party) j(HM_7)

ren party lab
decode lab, g(re_lab)
g byvar="Partisanship"

save "prpHM_party_FE.dta", replace


*** combining all estimates in one dataset

use "prpHM_issue_FE.dta", clear
append using "prpHM_global_FE.dta"
append using "prpHM_influence_FE.dta"
append using "prpHM_party_FE.dta"

g id=1 if byvar=="N of groups included in a model"
replace id=2 if byvar=="Partisanship"
replace id=3 if byvar=="General political ideology"
replace id=4 if byvar=="Issue"

label values lab .

save "prpHM_all_FE.dta", replace
